/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package pl.edu.agh.student.logic.service;

import java.util.List;
import org.jboss.seam.annotations.In;
import org.jboss.seam.annotations.Name;
import org.jboss.seam.annotations.Out;

import pl.edu.agh.student.logic.dao.ApplicationDao;
import pl.edu.agh.student.logic.dao.AttachmentDao;
import pl.edu.agh.student.logic.dao.GenericDao;
import pl.edu.agh.student.model.Application;
import pl.edu.agh.student.model.Attachment;
import pl.edu.agh.student.model.Customer;

/**
 *
 * @author janburkot
 */
@Name("applicationService")
public class ApplicationServiceImpl extends GenericServiceImpl<Application> implements ApplicationService {

    @In(value="applicationDao",create=true,required=false)
    @Out
    protected ApplicationDao dao;
    
    @In(value="attDao",required=false, create=true)
    @Out
    protected AttachmentDao attachmentDao;
    
    @Override
    public GenericDao<Application> getDao() {
        return dao;
    }

    public List<Application> getCustomerApplication(Customer person) {
        return dao.findByProperty("person", person);
    }

    public void addAttachment(Attachment att, Application app) {
        att.setApplication(app);
        attachmentDao.saveOrUpdate(att);
        dao.refresh(app);
        System.out.println(app.getAttachments());
        System.out.println(att.getApplication());
    }

    public void removeAttachment(Attachment att, Application app) {
        attachmentDao.delete(att);
        dao.refresh(app);
    }
}
